﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class user_profilestep : Wozuji.Logic.PageLogin
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            privance.DataSource = new Wozuji.BLL.region_t().GetModelList("region_code LIKE '%0000%' ORDER BY region_code");
            privance.DataTextField = "region_name";
            privance.DataValueField = "region_code";
            privance.DataBind();

;        }
        else
        {
            Wozuji.Common.MessageBox.ResponseScript(Page, "new Dialog('<table align=\\'center\\' width=\\'300px\\'><tr><td>保存成功！</td><td><a href=\\'/u/default.aspx\\'><input value=\\'进入我的足迹\\' class=\\'btnyellow150\\' type=\\'button\\' id=\\'btn_login\\'></a></td></tr></table>', { id:\'dialog1\' }).show();");
        }

    }
    protected void privance_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!privance.SelectedItem.Value.Trim().Equals("000000"))
        {
            w_local.Visible = false;

            Wozuji.BLL.region_t reg = new Wozuji.BLL.region_t();
            DataSet ds = reg.GetList("rtrim(region_code) like'" + privance.SelectedItem.Value.Substring(0, 2) + "%' and rtrim(region_code) like'%00'and rtrim(region_code) not like'%0000'");
            //清空下拉列表
            city.Items.Clear();
            //绑定下拉列表
            city.DataSource = ds.Tables[0];
            city.DataTextField = "region_name";
            city.DataValueField = "region_code";
            city.DataBind();




        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //判断输入，验证用户输入
        if (privance.SelectedItem.Value.Trim().Equals("000000"))
        {
            w_local.Visible = true;
            w_local.Text = "请选择您的居住地！";
            w_local.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            w_local.Visible = false;
           
            //判断旅游爱好
            string i_like = "";
            for (int i = 0; i < l_like.Items.Count; i++)
            {
                if (l_like.Items[i].Selected)
                {
                    if (i_like.Equals(""))
                    {
                        i_like = l_like.Items[i].Value;
                    }
                    else
                    {
                        i_like = i_like + "," + l_like.Items[i].Value;
                    }
                }
            }
            if (i_like.Equals(""))
            {
                w_like.Visible = true;
                w_like.Text = "请选择您的旅游爱好！";
                w_like.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                w_like.Visible = false;
                //做数据处理
                //得到用户信息
                try
                {
                    Wozuji.Model.Member_t mb = new Wozuji.Model.Member_t();
                    Wozuji.BLL.Member_t mbbill = new Wozuji.BLL.Member_t();
                    mb = mbbill.GetModel(Convert.ToInt32(Session["userid"].ToString()));
                    mb.Member_Sex = sex.SelectedItem.Value.ToString();
                    mb.Member_location = Convert.ToInt32(city.SelectedItem.Value.Trim().ToString());
                    mb.Member_Workfor = i_like;
                    mbbill.Update(mb);
                    Wozuji.Common.MessageBox.ResponseScript(Page, "new Dialog('<table align=\\'center\\' width=\\'300px\\'><tr><td>保存成功！</td><td><a href=\\'/u/default.aspx\\'><input value=\\'进入我的足迹\\' class=\\'btnyellow150\\' type=\\'button\\' id=\\'btn_login\\'></a></td></tr></table>', { id:\'dialog1\' }).show();");

                }
                catch (Exception ex)
                {

                }
            }
        }

    }
}